<?php

namespace App\Dao;

use App\Model\AnchorEvaluate;
use App\Utils\MemcacheClient;
use Hyperf\Context\ApplicationContext;

class AnchorEvaluateDao /*extends \App\Model\AnchorEvaluate*/
{
    private static $instance;

    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = Applicationcontext::getcontainer()->get(self::class);
        }
        return self::$instance;
    }


    public function getData($type = -1, $to_array = 0)
    {
        // $cache = MemcacheClient::getInstance()->get('anchor_evaluate_data_type_'.$type.'_to_array_'.$to_array);
        // if (empty($cache)) {
        if ($type == -1) {
            $data = AnchorEvaluate::query()->where('status', 1)->get();
        } else {
            $data = AnchorEvaluate::query()->where('type', $type)->where('status', 1)->orderBy('id')->get();
        }
        // var_dump($data);
        if ($to_array) {
            foreach ($data as $v) {
                $cache[$v['id']] = [
                    'content' => $v['content'],
                    'en_content' => $v['en_content'],
                    'color' => $v['color'],
                    'bg_color' => $v['bg_color']
                ];
            }
        } else {
            $cache = $data;
        }
        //     MemcacheClient::getInstance()->set('anchor_evaluate_data_type_'.$type.'_to_array_', $cache, 3600);
        // }
        return $cache;
    }

}